<%= simple_form_for(@department, data: {prevent_double_submit: ''}) do |f| %>
  <%= model_error_messages @department %>
  
  <div class="form-inputs">
    <%= f.input :name, label: 'Department Name:' %>
    
    <div id="permissions">
      <%= f.label :permissions, "Users:", class: 'field-label' %>
      <%= f.simple_fields_for :permissions do |permission| %>
        <%= render "permission_fields", :f => permission %>
      <% end %>
      <div class='add-fields'>
        <%= link_to_add_association 'add another user', 
          f, :permissions %>
      </div>
    </div>
  </div>

  <div class="form-actions">
    <%= f.button :submit %>
    <%= link_to 'Cancel', manage_departments_path %>
  </div>
<% end %>

<div id="user-modal" class="content-section" style="display:none;">
  <h2>Add New User</h2>
  <%= render 'users/form', user: User.new, modal: true %>
</div>
